{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Import packages"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sdmetrics.reports.utils import get_column_plot, get_column_pair_plot\n",
    "from sdmetrics.reports.single_table import QualityReport\n",
    "from sdv import Metadata\n",
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_real = pd.read_csv('data/olympics.csv')\n",
    "df_fake = pd.read_csv('generations/olympics_generation.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Define column types"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "continuous_columns = ['Age','Height', 'Weight']\n",
    "categorical_columns = ['Sex', 'Year', 'Season', 'City', 'Sport', 'Medal', 'AOS', 'AOE']\n",
    "df_real[continuous_columns] = df_real[continuous_columns].astype('int64')\n",
    "df_real[categorical_columns] = df_real[categorical_columns].astype('category')\n",
    "df_fake[continuous_columns] = df_fake[continuous_columns].astype('int64')\n",
    "df_fake[categorical_columns] = df_fake[categorical_columns].astype('category')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Add unique key for real and fake data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_real_plot = df_real.reset_index().rename(columns={'index': 'key'})\n",
    "df_fake_plot = df_fake.reset_index().rename(columns={'index': 'key'})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Set up metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "metadata = Metadata()\n",
    "metadata.add_table(name='olympic',\n",
    "                  data=df_real_plot,\n",
    "                  primary_key = 'key')\n",
    "metadata = metadata.get_table_meta('olympic')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generate evaludation report"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "my_report = QualityReport()\n",
    "my_report.generate(df_real_plot, df_fake_plot, metadata)\n",
    "score = my_report.get_score()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_column_plot(\n",
    "    real_data=df_real_plot,\n",
    "    synthetic_data=df_fake_plot,\n",
    "    metadata=metadata,\n",
    "    column_name='Height'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_column_plot(\n",
    "    real_data=df_real_plot,\n",
    "    synthetic_data=df_fake_plot,\n",
    "    metadata=metadata,\n",
    "    column_name='Sex'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_column_plot(\n",
    "    real_data=df_real_plot,\n",
    "    synthetic_data=df_fake_plot,\n",
    "    metadata=metadata,\n",
    "    column_name='City'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "get_column_plot(\n",
    "    real_data=df_real_plot,\n",
    "    synthetic_data=df_fake_plot,\n",
    "    metadata=metadata,\n",
    "    column_name='AOE'\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "my_report.get_visualization(property_name='Column Pair Trends')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
